package com.springcloud.demo.serverb.service;

import com.springcloud.demo.base.po.ServerB;
import com.springcloud.demo.serverb.mapper.IServerBMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Random;

@Service
public class ServerBServiceImpl {

    @Autowired
    private IServerBMapper serverBMapper;

    public void insert() throws Exception {
        ServerB serverB = ServerB.builder()
                .name("服务B")
                .insertDate(new Date())
                .build();
        Random random = new Random();
        if (random.nextInt(10) % 2 == 0) {
            throw new Exception("测试事务");
        }
        serverBMapper.insert(serverB);
    }
}
